/*
 * Copyright (C) 2020-present, kinbug All rights reserved.
 * 
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 *
 *     http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */
package com.gitee.kinbug.sniper.common.entity;

import java.math.BigDecimal;
import java.util.Date;

import com.alibaba.fastjson.JSON;
import com.gitee.kinbug.sniper.common.enums.CandleEnum;
import com.gitee.kinbug.sniper.common.util.CoreUtil;

import lombok.AllArgsConstructor;
import lombok.Builder;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

/**
 * -描述
 * @ClassName: KLine
 * @author kinbug
 * @date 2020-11-19
 */
@Data
@Builder
@AllArgsConstructor
@NoArgsConstructor
@Accessors(chain = true)
public class Bar {

	public long id;

	public BigDecimal open;

	public BigDecimal close;

	public BigDecimal low;

	public BigDecimal high;

	public BigDecimal amount;

	public BigDecimal vol;

	public BigDecimal count;

	public BigDecimal tradeTurnover;
	
	public String symbol;
	
	public Date klineDate;//k线得时间
	
	public CandleEnum candleEnum;
	
	/**
	 * - 是否是上涨
	 * @Title isUp
	 * @return boolean 返回类型
	 * @throws
	 */
	public boolean isUp() {
		return close.compareTo(open) > 0 ? true : false;
	}

	/**
	 * - 是否是下跌
	 * @Title isDown
	 * @return boolean 返回类型
	 * @throws
	 */
	public boolean isDown() {
		return close.compareTo(open) > 0 ? false : true;
	}

	/**
	 * - 获得涨跌幅%
	 * @Title getChangepercent
	 * @return boolean 返回类型
	 * @throws
	 */
	public double getChangepercent() {
		return CoreUtil.getChangepercent(this.open, this.close).doubleValue();
	}
	
	/**
	 * - 上下影线比率
	 * @Title getHatchRate
	 * @param isUp true求上影线，false求下影线
	 * @return boolean 返回类型
	 * @throws
	 */
	public double getHatchRate(boolean isUp) {
		if (isUp) {
			return CoreUtil.getChangepercent(this.getClose(), this.getHigh()).doubleValue();
		}else {
			return CoreUtil.getChangepercent(this.getLow(), this.getClose()).doubleValue();
		}
		
	}

	/* (非 Javadoc) 
	* <p>Title: toString</p> 
	* <p>Description: </p> 
	* @return 
	* @see java.lang.Object#toString() 
	*/
	@Override
	public String toString() {
		return JSON.toJSONString(this);
	}
	
}
